import AImage from '@/components/AImage';
import { Typography } from 'antd';

import { isShowButton } from '@/utils/util';

export const columns = ({ handleEdit, currentPermissions }) => [
  {
    title: '商品名称',
    dataIndex: 'itemName',
    hideInTable: true,
  },
  {
    title: '商品ID',
    dataIndex: 'itemId',
    hideInTable: true,
  },
  {
    title: '商品信息',
    dataIndex: 'companyName',
    align: 'left',
    width: 500,
    hideInSearch: true,
    render: (_, record) => (
      <div style={{ display: 'flex', alignItems: 'center' }}>
        <div>
          <AImage height={80} width={80} src={record.mainGraph} />
        </div>
        <div style={{ marginLeft: 12 }}>
          <Typography.Text
            ellipsis={{ tooltip: record.itemName, width: 450 }}
            style={{ fontSize: '14px' }}
          >
            {record.itemName}
          </Typography.Text>
          <div style={{ fontSize: '14px', color: '#1677ff' }}>ID:{record.itemId || '-'}</div>
        </div>
      </div>
    ),
  },
  {
    title: '售价',
    dataIndex: 'price',
    align: 'left',
    hideInSearch: true,
    render: (_, record) => `￥${record.price}`,
  },
  {
    title: '积分配比',
    dataIndex: 'consumerName',
    align: 'left',
    hideInSearch: true,
    render: (_, record) =>
      `￥${record.pointsItemPrice || 0}+${record.pointsItemScore || '-'}积分`,
  },
  {
    title: '操作',
    align: 'left',
    hideInSearch: true,
    render: (record) => (
      <div>
        {isShowButton(currentPermissions, 'sales:integralGoods:info') && (
          <a style={{ marginRight: 8 }} onClick={() => handleEdit('edit', record)}>编辑</a>
        )}
        {isShowButton(currentPermissions, 'sales:integralGoods:remove') && (
          <a onClick={() => handleEdit('delete', record)}>删除</a>
        )}
      </div>
    ),
  },
];
